/*
 * @lc app=leetcode.cn id=401 lang=javascript
 *
 * [401] 二进制手表
 */

// @lc code=start
/**
 * @param {number} num
 * @return {string[]}
 */
var readBinaryWatch = function (num) {
    if (num == 0) { return ["0:00"] }
    let map = new Map([[0.01, [0]], [0.02, [1]], [0.04, [2]], [0.08, [3]], [0.16, [4]], [0.32, [5]], [1, [0]], [2, [1]], [4, [2]], [8, [3]]])
    let arr1 = [1, 2, 4, 8]
    let arrFloat1 = [0.01, 0.02, 0.04, 0.08, 0.16, 0.32]
    let ans = []
    let helpInt = function (n) {
        if (n <= 0) return [0]
        if (n == 1) return arr1
        let temp = helpInt(n - 1)
        let ArrN = []
        for (let i = 0; i < 4; i++) {
            for (let j = 0; j < temp.length && !(map.get(temp[j])).includes(i); j++) {
                arr = map.get(temp[j]).slice()
                arr.push(i)
                let subAns = arr1[i] + temp[j]
                if (subAns < 12) ArrN.push(subAns)
                map.set(subAns, arr)

            }
        }
        return ArrN
    }
    let helpFloat = function (n) {
        if (n <= 0) return [0]
        if (n == 1) return arrFloat1
        let temp = helpFloat(n - 1)
        let ArrF = []
        for (let i = 0; i < 6; i++) {
            for (let j = 0; j < temp.length && !(map.get(temp[j])).includes(i); j++) {
                arr = map.get(temp[j]).slice()
                arr.push(i)
                let subAns = arrFloat1[i] + temp[j]
                if (subAns < 0.60) ArrF.push(subAns)
                map.set(subAns, arr)
            }
        }
        return ArrF
    }
    for (let i = 0; i < 4 && i <= num; i++) {
        let arrI = helpInt(i)
        let arrF = helpFloat(num - i)
        for (let p = 0; p < arrI.length; p++) {
            for (let j = 0; j < arrF.length; j++) {
                ans.push((arrI[p] *100+ arrF[j]*100)/100)
            }
        }
    }
    return ans.map((item) => {
        item = item.toString().split(".")
        if (!item[1]) {
            item[1] = "00"
        }
        if (item[1].length == 1) {
            item[1] = item[1] + "0"
        }
        if (item[1].length > 2) {
            item[1] = item[1].slice(0, 2)
        }
        return item[0] + ":" + item[1]
    })
}
// @lc code=end

readBinaryWatch(2)